package per.lance.easytomcat.net;


import java.io.BufferedOutputStream;
import java.io.IOException;
import java.util.HashMap;
import java.util.Set;


public class HttpRespone {
    String statusCode = "";
    HashMap<String, String> responeHeader = new HashMap<String, String>();
    byte[] responeBody;
    BufferedOutputStream bos;

    public String getStatusCode() {
        return statusCode;
    }

    public void setStatusCode(String statusCode) {
        this.statusCode = statusCode;
    }

    public HashMap<String, String> getResponeHeader() {
        return responeHeader;
    }

    public void setResponeHeader(HashMap<String, String> responeHeader) {
        this.responeHeader = responeHeader;
    }

    public byte[] getResponeBody() {
        return responeBody;
    }

    public void setResponeBody(byte[] responeBody) {
        this.responeBody = responeBody;
    }

    public BufferedOutputStream getBos() {
        return bos;
    }

    public void setBos(BufferedOutputStream bos) {
        this.bos = bos;
    }

    public void respone() throws IOException {

        StringBuffer stringBuffer = new StringBuffer();
        stringBuffer.append(statusCode);
        stringBuffer.append("\r\n");
        Set<String> set = responeHeader.keySet();
        for (String key : set) {
            String str = key + ": " + responeHeader.get(key);
            stringBuffer.append(str);
            stringBuffer.append("\r\n");
        }
        stringBuffer.append("\r\n");
        bos.write(stringBuffer.toString().getBytes());
        if(responeBody!=null) {
            bos.write(responeBody);
        }
        bos.flush();
        bos.flush();
        bos.close();
    }
}
